﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;


namespace Dot5Demo.Models
{
    /*
     演示抽象类的Json序列化以及多重继承的序列化和反序列化
     */

    /// <summary>
    /// 
    /// </summary>
    [DataContract]
    [KnownType("GetAllKnownTypes")]
    public abstract class User
    {
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public Role Role { get; set; }
        private static Type[] GetAllKnownTypes()
        {
            return TypeRegister.GetAllTypes_User();
        }
    }

    [DataContract]
    [KnownType("GetAllTypes")]
    public class UserA : User
    {
        [DataMember]
        public int NID { get; set; }
        private static Type[] GetAllTypes()
        {
            return TypeRegister.GetAllTypes_UserA();
        }
    }

    [DataContract]
    [KnownType(typeof(UserBA))]
    [KnownType(typeof(UserBB))]
    public class UserB : User
    {
        [DataMember]
        public double Value { get; set; }
    }

    [DataContract]
    public class UserBA : User
    {
        [DataMember]
        public int Value { get; set; }
    }

    [DataContract]
    public class UserBB : User
    {
        [DataMember]
        public string Value { get; set; }
    }

    [DataContract]
    public class UserAA:UserA
    {
        [DataMember]
        public string Txt { get; set; }
    }

    [DataContract]
    public class UserAB : UserA
    {
        [DataMember]
        public string Txt { get; set; }
    }

    [DataContract]
    [KnownType("GetAllTypes")]
    public abstract class Role
    {
        [DataMember]
        public string Name { get; set; }
        private static Type[] GetAllTypes()
        {
            return TypeRegister.GetAllTypes_Role();
        }
    }

    [DataContract]
    public class RoleA : Role
    {
        [DataMember]
        public int Value1 { get; set; }
    }

    [DataContract]
    public class RoleB : Role
    {
        [DataMember]
        public double Value1 { get; set; }
    }
}
